package xhwl.hmo.mall.views;

import android.content.Context;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshKernel;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.RefreshState;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;

import pl.droidsonroids.gif.GifImageView;
import xhwl.hmo.mall.R;

/**
 * Created by admin on 2017-11-08.
 */

public class RecommentRefreshHeader extends LinearLayout implements RefreshHeader {
    GifImageView gifView;
    int  height;
    ImageView ivHeader;
    public RecommentRefreshHeader(Context context) {
        this(context,null);
    }

    public RecommentRefreshHeader(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.header_recomend,this);
        gifView= (GifImageView) findViewById(R.id.gifView);
        LinearLayout llHeader= (LinearLayout) findViewById(R.id.llHeader);
        llHeader.measure(0,0);
        //获取组件的高度  
        height=llHeader.getMeasuredHeight();
        ivHeader= (ImageView) findViewById(R.id.ivHeader);
        ivHeader.measure(0,0);
    }
    public int getHeaderHeight(){
        return height;
    }
    @Override
    public void onPullingDown(float percent, int offset, int headerHeight, int extendHeight) {

    }

    @Override
    public void onReleasing(float percent, int offset, int headerHeight, int extendHeight) {

    }

    @NonNull
    @Override
    public View getView() {
        return this;
    }

    @Override
    public SpinnerStyle getSpinnerStyle() {
        return SpinnerStyle.FixedBehind;
    }

    @Override
    public void setPrimaryColors(@ColorInt int... colors) {

    }

    @Override
    public void onInitialized(RefreshKernel kernel, int height, int extendHeight) {

    }

    @Override
    public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) {

    }

    @Override
    public void onStartAnimator(RefreshLayout layout, int height, int extendHeight) {

    }

    @Override
    public int onFinish(RefreshLayout layout, boolean success) {
        return 500;
    }

    @Override
    public boolean isSupportHorizontalDrag() {
        return false;
    }

    @Override
    public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {
        switch (newState) {
            case None:
            case PullDownToRefresh:
                gifView.setVisibility(View.INVISIBLE);
                break;
            case Refreshing:
                gifView.setVisibility(View.VISIBLE);
                break;
            case ReleaseToRefresh:
                gifView.setVisibility(View.INVISIBLE);
                break;
        }

    }
}
